/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package RecClient;

import blue.laggoon.ppe.AccesBDD;
import blue.laggoon.ppe.MainPannel;
import java.awt.*;
import java.text.*;
import javax.swing.*;
import javax.swing.text.*;

/**
 *
 * @author Etudiant
 */
public class RecClient extends javax.swing.JFrame
{
    private Object jFormattedTFCPActionPerformed;
    
    /**
     * Creates new form RecClient
     */
    public RecClient() // Constructeur
    {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BtValid = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        TFNom = new javax.swing.JTextField();
        TFAdresse = new javax.swing.JTextField();
        TFCP = new javax.swing.JTextField();
        TFVille = new javax.swing.JTextField();
        TFTel = new javax.swing.JTextField();
        TFMail = new javax.swing.JTextField();
        TFPrenom = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        emptyAreas = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        CategTarif = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        BtValid.setIcon(new javax.swing.ImageIcon(getClass().getResource("/blue/laggoon/ppe/ressources/validation.png"))); // NOI18N
        BtValid.setText("Valider");
        BtValid.setName("BtValid"); // NOI18N
        BtValid.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtValidActionPerformed(evt);
            }
        });

        jLabel1.setText("Nom:");

        jLabel2.setText("Prénom:");

        jLabel3.setText("Adresse:");

        jLabel4.setText("Code Postal:");

        jLabel5.setText("Ville:");

        jLabel6.setText("Téléphone: ");

        jLabel7.setText("Mail:");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        jLabel8.setText("Enregistrement Client");

        TFNom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TFNomActionPerformed(evt);
            }
        });

        TFAdresse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TFAdresseActionPerformed(evt);
            }
        });

        TFCP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TFCPActionPerformed(evt);
            }
        });

        TFVille.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TFVilleActionPerformed(evt);
            }
        });

        TFTel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TFTelActionPerformed(evt);
            }
        });

        TFMail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TFMailActionPerformed(evt);
            }
        });

        TFPrenom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TFPrenomActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/blue/laggoon/ppe/ressources/return.png"))); // NOI18N
        jButton1.setText("Retour à l'accueil");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        emptyAreas.setFont(new java.awt.Font("Trebuchet MS", 0, 18)); // NOI18N

        jLabel10.setText("Catégorie clientl:");

        CategTarif.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Plein", "Réduit", "Vermeil", "Scolaire", "Club" }));
        CategTarif.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CategTarifActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(94, Short.MAX_VALUE)
                        .addComponent(jLabel8))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(56, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(TFVille, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(TFTel, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(TFMail, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(CategTarif, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel4)
                                            .addComponent(jLabel3)
                                            .addComponent(jLabel2)
                                            .addComponent(jLabel1))
                                        .addGap(47, 47, 47)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(TFNom, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
                                            .addComponent(TFPrenom)
                                            .addComponent(TFAdresse)
                                            .addComponent(TFCP)))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(emptyAreas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jButton1)
                                            .addGap(70, 70, 70)
                                            .addComponent(BtValid, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addGap(27, 27, 27))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jLabel1))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TFNom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(TFPrenom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFAdresse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFCP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFVille, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(CategTarif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addComponent(emptyAreas, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtValid, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TFNomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TFNomActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TFNomActionPerformed

    private void TFPrenomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TFPrenomActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TFPrenomActionPerformed

    private void TFAdresseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TFAdresseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TFAdresseActionPerformed

    private void TFCPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TFCPActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TFCPActionPerformed

    private void TFVilleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TFVilleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TFVilleActionPerformed

    private void TFTelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TFTelActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TFTelActionPerformed

    private void TFMailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TFMailActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TFMailActionPerformed

    private void BtValidActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtValidActionPerformed
        /// Appel de la méthode Login de la classe AccesBdd
        String nom = TFNom.getText();
        String prenom = TFPrenom.getText();
        String adresse = TFAdresse.getText();
        String cp = TFCP.getText();
        String ville = TFVille.getText();
        String tel = TFTel.getText();
        String mail = TFMail.getText();
        
        String tarif = (String)CategTarif.getSelectedItem();
        Integer idTarif = 0;
        // Déterminer l'id du tarif en fonction du label
        
        switch (tarif)
        {
            case "Plein": idTarif = 1;
                     break;
            case "Réduit": idTarif = 2;
                     break;
            case "Vermeil":idTarif = 3;
                     break;
            case "Scolaire": idTarif = 4;
                     break;
            case "Club": idTarif = 5;
                     break;
        }
        
            if((TFNom.getText() == "") || (TFPrenom.getText() == "") || (TFAdresse.getText() == "") || (TFCP.getText() == "") || (TFVille.getText() == "")) // Vérification si ces 5 champs obligatoires ont été remplis ou non.
            {
                emptyAreas.setText("Vous n'avez pas rempli tous les champs obligatoires, veuillez réessayer.");
            }
            else 
            {
                try
                {
                    AccesBDD.set_client(nom, prenom, adresse, cp, ville, tel, mail, idTarif);
                    emptyAreas.setText("Les coordonnées du client ont bien été enregistrées.");
                }
                catch(Exception e)
                {
                    System.out.println("Une erreur est survenue: "+e);
                }
            }
        
    }//GEN-LAST:event_BtValidActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        MainPannel main = new MainPannel();
        main.setVisible(true);
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void CategTarifActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CategTarifActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CategTarifActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(RecClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(RecClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(RecClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(RecClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new RecClient().setVisible(true);
            }
        });
    }

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtValid;
    private javax.swing.JComboBox CategTarif;
    private javax.swing.JTextField TFAdresse;
    private javax.swing.JTextField TFCP;
    private javax.swing.JTextField TFMail;
    private javax.swing.JTextField TFNom;
    private javax.swing.JTextField TFPrenom;
    private javax.swing.JTextField TFTel;
    private javax.swing.JTextField TFVille;
    private javax.swing.JLabel emptyAreas;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    // End of variables declaration//GEN-END:variables
}
